package com.whut.googleplay.activity;

import android.support.v4.view.ViewPager;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.whut.googleplay.R;
import com.whut.googleplay.adapter.MainPageAdapter;
import com.whut.googleplay.fragment.BaseFragment;
import com.whut.googleplay.utils.FragmentFactory;
import com.whut.googleplay.widget.PagerTab;


/**
 * ============================================================
 * 作 者 :        xyb
 * 版 本 :        1.0
 * 创建日期 ：     2016-04-20 下午12:47
 * 描 述 ： 主Activity,每个viewpager实际上是一个fragment
 * 修订历史 ：
 * ============================================================
 **/

@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @ViewInject(value = R.id.tabs)
   private PagerTab mTabs;

    @ViewInject(value = R.id.vp_content)
    private ViewPager vpContent;


    @Override
    public void initView() {
        ViewUtils.inject(this);
        MainPageAdapter adapter = new MainPageAdapter(getSupportFragmentManager());
        vpContent.setAdapter(adapter);

        //绑定到一起
        mTabs.setViewPager(vpContent);
        mTabs.setOnPageChangeListener(this);
    }

    @Override
    public void initData() {

    }


    @Override
    public void onPageSelected(int position) {
        BaseFragment baseFragment = FragmentFactory.createFragment(position);
        baseFragment.show();
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }

}
